package cn.org.zx.password.ctrl;

import java.io.IOException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;

import cn.org.zx.password.blh.PassWordBlh;
import cn.org.zx.common.aop.BeanFactory;
import cn.org.zx.common.commutils.Json;

public class PassWordCtrl extends MultiActionController{
	private PassWordBlh passwordblh;
		
	public PassWordCtrl(){
		passwordblh = (PassWordBlh)BeanFactory.getBean(new PassWordBlh());	
	}
	
	//根据aid找帐号及名称
	public ModelAndView getPassWordUpdateInit(HttpServletRequest request,HttpServletResponse response) throws UnsupportedEncodingException {
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		
		Map mapData = request.getParameterMap();
		Map mapReturn = passwordblh.getPassWordUpdateInit(mapData);
		
		//直接返回
		return new ModelAndView("changepwd.jsp",mapReturn);
	}
	
	//密码修改保存
	public ModelAndView getPassWordUpdateSave(HttpServletRequest request,HttpServletResponse response) throws UnsupportedEncodingException {
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		
		Map mapData = request.getParameterMap();		
		Map mapReturn = passwordblh.getPassWordUpdateSave(mapData);
		
		PrintWriter out = null;
		try {
			out = response.getWriter();
			String result = Json.toJson(mapReturn);
			out.print(result);
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
	}
	
}
